package com.fwx.mybatis_03.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author : fengwenxiang
 * @date : 2022/6/18 11:07
 * @description：
 */
public class MybatisUtil {
    private static SqlSessionFactory sqlSessionFactory;
    static {
        String src = "mybatis03-config.xml";
        try {
            InputStream resourceAsStream = Resources.getResourceAsStream(src);
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    public static SqlSession getSqlSession(){
        return sqlSessionFactory.openSession(true);
    }
}
